#include <stdio.h>
#include <stdlib.h>
#include "asc_decoder.h"


#define SAMPLESLEN 320 
#define HALF_SAMPLESLEN SAMPLESLEN/2

short	inbuf[HALF_SAMPLESLEN] = {0};
short	outbuf[SAMPLESLEN] = {0};

FILE     *fp_in,*fp_out;
short    n;
short    Samplelen,Bitstreamlen;
short    codec,agc,ns;

main( int argc, char *argv[ ])
{

	if(argc!=6)
	{
		printf("Please input :[input filename][output filename] [codec]\n");
	}
	
	if( (fp_in=fopen(argv[1],"rb"))==NULL )
	{	
		printf("Can't read file !\n");
	}

	if( (fp_out=fopen(argv[2],"wb"))==NULL )
	{	
		printf("Can't write file !\n");
	}

    codec = atoi(argv[3]);
    agc = atoi(argv[4]);
    ns = atoi(argv[5]);

	Bitstreamlen = ASC_Decoder_Init(codec);
	ASC_Set_Parameter (agc, ns);//open agc and nr, 必须写在函数ASC_Decoder_Init之后
	if(Bitstreamlen == 0) 
	{
		printf("ASC_Decoder_Init error !\n");
		return 0;
	}

	while( fread(inbuf, sizeof(short), Bitstreamlen, fp_in) == (unsigned)Bitstreamlen)
	{
			
		Samplelen = ASC_Decoder(inbuf, outbuf, Bitstreamlen, codec);

		fwrite(outbuf,sizeof(short),Samplelen,fp_out);	

	}
	
	fcloseall();
	return 0;
}

